package method;

/**
 * @author DCSGO
 * @version 1.0
 * 1.主线程每隔1s，输出hi,一共10次
 * 2.当输出到hi5时，启动一个子线程(要求实现Runnable)，
 * 每隔1s输出hello，等该线程输出10次hello后，退出
 * 3.主线程继续输出hi，直到主线程退出.
 */
public class ThreadMethodExercise {
    public static void main(String[] args) throws InterruptedException {
        for (int i = 1; i <= 10; i++) {
            System.out.println("hi " + i);
            if (i == 5) {
                T3 t3 = new T3();
                Thread threadT3 = new Thread(t3);
                threadT3.start();
                threadT3.join();
            }
            Thread.sleep(1000);
        }
        /*
         * hi 1
         * hi 2
         * hi 3
         * hi 4
         * hi 5
         * hello 1
         * hello 2
         * hello 3
         * hello 4
         * hello 5
         * hello 6
         * hello 7
         * hello 8
         * hello 9
         * hello 10
         * hi 6
         * hi 7
         * hi 8
         * hi 9
         * hi 10
         *
         * 进程已结束，退出代码为 0
         */
    }
}

class T3 implements Runnable {
    @Override
    public void run() {
        for (int i = 1; i <= 10; i++) {
            System.out.println("hello " + i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
